package com.ymatou.iapi.trading.useranalysis.testcase;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.useranalysis.parameter.GetBuyerOrderStatisticsBean;
import com.ymatou.iapi.trading.useranalysis.parameter.resp.BuyerOrderStatisticsDetail;
import com.ymatou.iapi.trading.useranalysis.service.GetBuyerOrderStatisticsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.mongo.BuyerSellerOrderStatisticsMongoBean;
import com.ymttest.database.mongo.UserAnalysisMongoWapper;
import com.ymttest.utils.YMTDateUtil;
/**
*获取买家在指定卖家下的订单统计信息接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetBuyerOrderStatistics {
	private static GetBuyerOrderStatisticsBean req;
	private static GetBuyerOrderStatisticsCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取买家在指定卖家下的订单统计信息接口");
	}

	@Before
	public void caseUp() {
		req = new GetBuyerOrderStatisticsBean();
		call = new GetBuyerOrderStatisticsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void verify() {

	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBuyerOrderStatistics_001() {
		Logger.start(true, "首单支付时间大于5天");
		try {

			UserAnalysisMongoWapper buyerSellerOrderStatistics = new UserAnalysisMongoWapper();

			long id = 129905980267063012L;

			long buyerId = 30246093;
			long sellerId = 288484;

			BuyerSellerOrderStatisticsMongoBean buyerSellerOrderStatisticsvo = buyerSellerOrderStatistics
					.findById(id);

			Date date = buyerSellerOrderStatisticsvo.getFirstPaidTime();

			Logger.info("date:"
					+ YMTDateUtil.getFormatTime(date, YMTDateUtil.YMDHMSS));

			buyerSellerOrderStatistics.updateFirstPaidTime(id,
					YMTDateUtil.getBeforeOrNextDate(new Date(), -5), false);

			Logger.info("date2:"
					+ YMTDateUtil.getFormatTime(buyerSellerOrderStatistics
							.findById(id).getFirstPaidTime(),
							YMTDateUtil.YMDHMSS));

			req.setBuyerId(buyerId);
			req.setSellerIds(Arrays.asList(sellerId));

			call.setData(req);
			call.callService();

			Map<Long, BuyerOrderStatisticsDetail> map = call
					.getBuyerOrderStatisticsResp().getFromSeller();

			Logger.verifyEquals(true, map.get(sellerId).isVipCustomer(),
					"校验是否为vip价客户");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBuyerOrderStatistics_002() {
		Logger.start(true, "首单支付时间小于5天");
		try {

			UserAnalysisMongoWapper buyerSellerOrderStatistics = new UserAnalysisMongoWapper();

			long id = 129905980267063012L;

			long buyerId = 30246093;
			long sellerId = 288484;

			BuyerSellerOrderStatisticsMongoBean buyerSellerOrderStatisticsvo = buyerSellerOrderStatistics
					.findById(id);

			Date date = buyerSellerOrderStatisticsvo.getFirstPaidTime();

			Logger.info("date:"
					+ YMTDateUtil.getFormatTime(date, YMTDateUtil.YMDHMSS));

			buyerSellerOrderStatistics.updateFirstPaidTime(id,
					YMTDateUtil.getBeforeOrNextDate(new Date(), -4), false);

			Logger.info("date2:"
					+ YMTDateUtil.getFormatTime(buyerSellerOrderStatistics
							.findById(id).getFirstPaidTime(),
							YMTDateUtil.YMDHMSS));

			req.setBuyerId(buyerId);
			req.setSellerIds(Arrays.asList(sellerId));

			call.setData(req);
			call.callService();

			Map<Long, BuyerOrderStatisticsDetail> map = call
					.getBuyerOrderStatisticsResp().getFromSeller();

			Logger.verifyEquals(false, map.get(sellerId).isVipCustomer(),
					"校验是否为vip价客户");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBuyerOrderStatistics_003() {
		Logger.start(true, "新用户支付后取消订单");
		try {

			UserAnalysisMongoWapper buyerSellerOrderStatistics = new UserAnalysisMongoWapper();

			long id = 129905984562030308L;

			long buyerId = 30246094;
			long sellerId = 288484;

			BuyerSellerOrderStatisticsMongoBean buyerSellerOrderStatisticsvo = buyerSellerOrderStatistics
					.findById(id);

			Date date = buyerSellerOrderStatisticsvo.getFirstPaidTime();
			/*
						Logger.info("date:"
								+ YMTDateUtil.getFormatTime(date, YMTDateUtil.YMDHMSS));

						buyerSellerOrderStatistics.updateFirstPaidTime(id,
								YMTDateUtil.getBeforeOrNextDate(new Date(), -5));

						Logger.info("date2:"
								+ YMTDateUtil.getFormatTime(buyerSellerOrderStatistics
										.findById(id).getFirstPaidTime(),
										YMTDateUtil.YMDHMSS));
			*/
			req.setBuyerId(buyerId);
			req.setSellerIds(Arrays.asList(sellerId));

			call.setData(req);
			call.callService();

			Map<Long, BuyerOrderStatisticsDetail> map = call
					.getBuyerOrderStatisticsResp().getFromSeller();

			Logger.verifyEquals(true, map.get(sellerId).isNewCustomer(),
					"校验是否为新用户价客户");

			Logger.verifyEquals(false, map.get(sellerId).isVipCustomer(),
					"校验是否为vip价客户");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetBuyerOrderStatistics_004() {
		Logger.start(true, "首单支付时间大于5天,跨年跨月");
		try {

			UserAnalysisMongoWapper buyerSellerOrderStatistics = new UserAnalysisMongoWapper();

			long id = 129905980267063012L;

			long buyerId = 30246093;
			long sellerId = 288484;

			BuyerSellerOrderStatisticsMongoBean buyerSellerOrderStatisticsvo = buyerSellerOrderStatistics
					.findById(id);

			Date date = buyerSellerOrderStatisticsvo.getFirstPaidTime();

			Logger.info("date:"
					+ YMTDateUtil.getFormatTime(date, YMTDateUtil.YMDHMSS));

			buyerSellerOrderStatistics.updateFirstPaidTime(id,
					YMTDateUtil.getBeforeOrNextDate(new Date(), -365), false);

			Logger.info("date2:"
					+ YMTDateUtil.getFormatTime(buyerSellerOrderStatistics
							.findById(id).getFirstPaidTime(),
							YMTDateUtil.YMDHMSS));

			req.setBuyerId(buyerId);
			req.setSellerIds(Arrays.asList(sellerId));

			call.setData(req);
			call.callService();

			Map<Long, BuyerOrderStatisticsDetail> map = call
					.getBuyerOrderStatisticsResp().getFromSeller();

			Logger.verifyEquals(true, map.get(sellerId).isVipCustomer(),
					"校验是否为vip价客户");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}